package Enums;

public enum POSTATE {
    NEW(0,"New PO"), APPROVED(10, "Approved"), ONORDER(20, "OnOrder"), RECEIVED(30, "Rcvd");

    private final int code;
    private final String desc;

    private POSTATE(int c, String s){
        code = c;
        desc = s;
    }

    public int getState(){
        return code;
    }

    public String getDesc(){
        return desc;
    }
    
    public static POSTATE getStateFromDesc(final String desc){
    	if(desc.equals("New PO")){
    		return NEW;
    	} else if(desc.equals("Approved")){
    		return APPROVED;
    	} else if(desc.equals("OnOrder")){
    		return ONORDER;
    	} else if(desc.equals("Rcvd")){
    		return RECEIVED;
    	} else {
    		return RECEIVED;
    	}
    }
    
    public static POSTATE getStateFromInt(final int state) {
        switch (state) {
        case 0:
            return NEW;
        case 10:
            return APPROVED;
        case 20:
            return ONORDER;
        case 30:
            return RECEIVED;
        default:
            throw new EnumConstantNotPresentException(POSTATE.class, String.valueOf(state));
        }
    }
}
